package reduce.fz.com.reduce.util.base;

import android.content.Context;
import android.os.Handler;
import android.os.Message;


import cn.smssdk.EventHandler;
import cn.smssdk.SMSSDK;
import reduce.fz.com.reduce.util.ToastUtil;

/**
 * Created by qingshengzheng on 15/11/23.
 */
public class SMSManager {
    private static String appkey = "d9651ee354e8";
    private static String appsecret = "ffa6495387b06850a0c51330458ff993";

    public static SMSLinstener smsLinstener;
    public static Handler handler;

    public static EventHandler eh = new EventHandler() {

        @Override
        public void afterEvent(int event, int result, Object data) {
            Message msg = new Message();
            msg.arg1 = event;
            msg.arg2 = result;
            msg.obj = data;
            handler.sendMessage(msg);
        }

    };


    public static void setSMSLinstener(SMSLinstener linstener) {
        smsLinstener = linstener;
    }

    public static void init(Context context) {
        SMSSDK.initSDK(context, appkey, appsecret);
        SMSSDK.registerEventHandler(eh);
    }

    public interface SMSLinstener {

        //提交验证码，用于验证
        public void subVCode(Object data);

        //向手机客户端发送验证码成功
        public void sendVcode(Object data);
    }

    public static void submitVcode(String mobile, String vcode) {
        SMSSDK.submitVerificationCode("86", mobile, vcode);
    }

    public static void getVcode(String mobile) {
        SMSSDK.getVerificationCode("86", mobile);
    }

    public static  void unregister()
    {
        SMSSDK.unregisterAllEventHandler();
    }


}

